/*
 * Logger.cpp
 *
 *  Created on: 05-08-2011
 *      Author: cristian
 */

#include "Logger.h"

Logger::Logger() {

}

Logger::~Logger() {

}

void Logger::hal_trace(const char* component, int color, const char* function, const char* file, int line, const char* format, ...)
{
	char *color_function = new char;
	char *color_fileline = new char;

	va_list args;
	struct timeval tv;
	struct timezone tz;

	gettimeofday(&tv, &tz);

	switch(color) {

		case TRACE_CORE:
		strcpy(color_function ,ANSI_YELLOW);
		strcpy(color_fileline , ANSI_WHITE);
		break;
		case TRACE_CLIENT:
		strcpy(color_function , ANSI_BLUE);
		strcpy(color_fileline ,ANSI_WHITE);
		case TRACE_SERVER:
		strcpy(color_function , ANSI_GREEN);
		strcpy(color_fileline ,ANSI_RED);
		break;
	}
	va_start( args, format );
	printf("TRACE~ %s%2i.%i%s %s%s[%s%s%s%s%s|%s:%i%s] %s%s():%s ",
			ANSI_CYAN, (int) (tv.tv_sec - Logger::init_time), (int) tv.tv_usec, ANSI_RESET,
			ANSI_MAGENTA, ANSI_BOLD,
			ANSI_RESET, ANSI_BOLD, ANSI_GREEN, component, color_fileline, file,
			line, ANSI_MAGENTA,
			color_function, function, ANSI_RESET);
	vprintf(format, args );
	va_end(args);
	printf("%s\n", ANSI_RESET);
	fflush(stdout);
	delete color_function;
	delete color_fileline;
}

void Logger::hal_error(const char* component, int color, const char* function, const char* file, int line, const char* format, ...)
{
	char *color_function = new char;
	char *color_fileline = new char;

	va_list args;
	struct timeval tv;
	struct timezone tz;

	gettimeofday(&tv, &tz);

	switch(color) {

		case TRACE_CORE:
		strcpy(color_function ,ANSI_YELLOW);
		strcpy(color_fileline , ANSI_WHITE);
		break;
		case TRACE_CLIENT:
		strcpy(color_function , ANSI_BLUE);
		strcpy(color_fileline ,ANSI_WHITE);
		case TRACE_SERVER:
		strcpy(color_function , ANSI_GREEN);
		strcpy(color_fileline ,ANSI_RED);
		break;
	}
	va_start( args, format );
	printf("%sERROR~ %s%2i.%i%s %s%s[%s%s%s%s%s|%s:%i%s] %s%s():%s ",ANSI_RED,
			ANSI_RED, (int) (tv.tv_sec - Logger::init_time), (int) tv.tv_usec, ANSI_RESET,
			ANSI_RED, ANSI_RED,
			ANSI_RESET, ANSI_RED, ANSI_RED, component, color_fileline, file,
			line, ANSI_MAGENTA,
			color_function, function, ANSI_RED);
	vprintf(format, args );
	va_end(args);
	printf("%s\n", ANSI_RESET);
	fflush(stdout);
	delete color_function;
	delete color_fileline;
}

